'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = 'hi, egg';
  }
  async login(){
    const {ctx,app} = this
    const {user_name,user_pwd} = ctx.request.body

    if(user_name && user_pwd){
      // 生成token
      const userInfo = {
        name:"lufei",
        role:'超级管理员',
        login_time:Date.now()/1000,
        end_time:Date.now()/1000+3600*2
      }
      const token = app.jwt.sign(userInfo,app.config.jwt.sercet)

      ctx.body = {
        code:0,
        msg:"登录成功",
        token
      };
    }else{
      ctx.body = {
        code:40006,
        msg:"缺少必要参数",
      };
    }
  }
}

module.exports = HomeController;
